package com.example.myapplication.volunteerservice;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.myapplication.Config.OKHttpTool;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.VoluntreelistBean;
import com.example.myapplication.apter.VoluntreelistApter;


public class MyhelpFragment extends Fragment {


    private View view;
    private RecyclerView review;
    private Handler handler;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_myhelp, container, false);
        initview();
        //志愿活动列表
        voluntreelist();
        return view;
    }

    private void voluntreelist() {
        OKHttpTool.doNetRequest("prod-api/api/volunteer-service/activity/list",
                OKHttpTool.GET,
                VoluntreelistBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        handler.post(new Runnable() {
                            @Override
                            public void run() {
                                VoluntreelistBean voluntreelistBean = (VoluntreelistBean)obj;
                                if(voluntreelistBean.getCode()==200){

                                }
                                review.setLayoutManager(new LinearLayoutManager(MyhelpFragment.this.getContext()));
                                review.setAdapter(new VoluntreelistApter(MyhelpFragment.this.getContext(),voluntreelistBean.getRows()));
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                }
        );
    }

    private void initview() {
        review = view.findViewById(R.id.review);
        handler = new Handler();
    }
}